package com.edu.project.mvp.presenter;

import com.edu.project.bean.HttpResult;
import com.edu.project.bean.UserData;
import com.edu.project.http.HttpResultSubscriber;
import com.edu.project.mvp.model.UserModeImpl;
import com.edu.project.mvp.view.UserView;

/**
 * Created by sheng on 2016/11/5.
 */
public class UserListImpl implements UserPresenter {

    public UserView mUserview;

    public UserModeImpl mUsermodeImpl;

    public UserListImpl(UserView view){
        this.mUserview = view;
        this.mUsermodeImpl = new UserModeImpl();
    }


    @Override
    public void loadUserData(int PageIndex, int PageSize) {
        if(PageIndex == 1){
            mUserview.showProgress();
        }
        mUsermodeImpl.loadData(PageIndex,PageSize,new HttpResultSubscriber<HttpResult<UserData>>(){

            @Override
            public void onResultSuccess(HttpResult<UserData> userDataResults) {
                super.onResultSuccess(userDataResults);
                mUserview.hideProgress();
                mUserview.addData(userDataResults.getData());
            }

            @Override
            public void onResultError(Throwable e) {
                super.onResultError(e);
                mUserview.hideProgress();
                mUserview.showLoadFail(e.getMessage());
            }
        });
    }



}
